<%extends"admin/base.html"%><%block content%>
<div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">ID</label>
            <div class="layui-input-inline">
              <input type="text" name="Id" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">评论者</label>
            <div class="layui-input-inline">
              <input type="text" name="nickname" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-comm" data-type="reload" lay-submit lay-filter="LAY-app-contcomm-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <button class="layui-btn layuiadmin-btn-comm" data-type="batchdel">删除</button>
        </div>
        <table id="LAY-app-content-comm" lay-filter="LAY-app-content-comm"></table>
        <script type="text/html" id="table-content-com">
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>回复</a>
          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
     <script type="text/html" id="stateTpl">
      {{#  if(d.state == true){ }}
            <button class="layui-btn layui-btn-xs layui-btn-warm">已回复</button>
          {{#  } else { }}
            <button class="layui-btn layui-btn-danger layui-btn-xs">未回复</button>
          {{#  } }}
    </script>
      </div>
    </div>
<%endblock%>
<%block script%>
//监听搜索
    form.on('submit(LAY-app-contcomm-search)', function(data){
      var field = data.field;

      //执行重载
      table.reload('LAY-app-content-comm', {
        where: field,
        method:'post'
      });
    });

    //点击事件
    var active = {
      batchdel: function(){
        var checkStatus = table.checkStatus('LAY-app-content-comm')
        ,checkData = checkStatus.data; //得到选中的数据

        if(checkData.length === 0){
          return layer.msg('请选择数据');
        }

        layer.confirm('确定删除吗？', function(index) {

          $.each(checkData,function(index,item){
                 //执行 Ajax 后重载
                  $.ajax({
                    url: "<< url_for('admin.ReplyDel') >>",
                    data:{Id:item.Id},
                    success: function (returnData) {
                        if (returnData.status == 1) {
                            layer.msg('已删除，ID:'+item.Id);
                        }
                        else {
                            layer.msg('ID:'+item.Id+'，'+returnData.info);
                        }
                     }
                  });
            });
            table.reload('LAY-app-content-comm');
        });
      }
    }

    $('.layui-btn.layuiadmin-btn-comm').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  table.render({
        elem: "#LAY-app-content-comm",
        url: "<< url_for('admin.ReplyList') >>",
        method:'post',
        cols: [[{type: "checkbox", fixed: "left"},
            {field: "Id",width: 100,title: "ID",sort: !0},
            {field: "blogName", title: "评论博文标题",width:350,minwidth:300},
            {field: "userName", title: "评论者"},
            {field: "content",title: "评论内容",width:350,minwidth:300},
             {field: "state",title: "状态",templet: "#stateTpl"},
            {field: "createTime", title: "评论时间", sort: !0},
            {title: "操作",width: 150,align: "center",fixed: "right",toolbar: "#table-content-com"}
        ]],
        page: !0,
        limit: 15,
        limits: [10, 15, 20, 25, 30],
        text: {
            none: '暂无相关数据',
            error:'对不起，加载出现异常！'
        }
    }), table.on("tool(LAY-app-content-comm)", function (t) {
        e=t.data;
        "del" === t.event ? layer.confirm("确定删除此条评论？", function (er) {
            console.log(e);
            $.ajax({
                url: "<< url_for('admin.ReplyDel') >>",
                data:{Id:e.Id},
                success: function(returnData) {
                    if (returnData.status == 1) {
                        table.reload('LAY-app-content-comm');
                        layer.msg('已删除，'+e.title);
                        t.del()
                    }
                    else {
                        layer.msg(e.title+'，'+returnData.info);
                    }
                 }
              });
        }) : "edit" === t.event && layer.open({
            type: 2,
            title: "回复评论",
            content: "/admin/reply/reply/" + e.Id,
            area: ["500px", "300px"],
            btn: ["确定", "取消"],
            yes: function (e, i) {
                var l = window["layui-layer-iframe" + e],
                a = i.find("iframe").contents().find("#layuiadmin-app-form-edit");
                a.click();
            }
        })
    })
    $('.layui-nav-child dd').removeClass('layui-this');
    $('#view_admin_reply_list').addClass('layui-this');
    $('.layui-nav-tree li').removeClass('layui-nav-itemed');
    $('#admin_blog_nav').addClass('layui-nav-itemed');
<%endblock%>